﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMN.Entity;
using CMN.Common;
using CMN.Framework;
using CMN.BLL;
namespace CMN.UI
{
    /// <summary>
    /// 标签解析
    /// </summary>
    public class AllShowDisplay
    {
        static AllShowDisplay()
        {
            BaseTemplateDisplay.OnNVelocityLoadPath += new EventHandler<TemplateArg>(downLoadPath);
            BaseTemplateDisplay.OnOtherPageDisplay += new EventHandler<TemplateDisplayArg>(downDisplay);
        }

        /// <summary>
        /// 绑定模板
        /// </summary>
        /// <param name="o"></param>
        /// <param name="arg"></param>
        private static void downDisplay(object o, TemplateDisplayArg arg)
        {
            if (arg.PageHelper.OtherTypeName == "indexShow")
            {
                BLLHelper bll = new BLLHelper();
                string strCount = bll.ExecuteScalar("select count(1) from Module_Article where enabled=1 and ispass=1 ");
                int intCount = Utils.StringToInt(strCount, 0);
                List<Module_ListInfo> lists = new List<Module_ListInfo>();
                
               
                for (int i = intCount; i > 0; i = i - 50)
                {
                    
                    Module_ListInfo list = new Module_ListInfo();
                    string page = (i / 50+1).ToString();
                    list.Url = string.Concat("/AllShow/", page);
                    list.Title = page;
                    lists.Add(list);

                }
                arg.NvelocityTemplate.Put("indexShow", lists);
            }
           
        }

        /// <summary>
        /// 加载模板路径
        /// </summary>
        /// <param name="o"></param>
        /// <param name="arg"></param>
        private static void downLoadPath(object o, TemplateArg arg)
        {
            if (arg.PageHelper.OtherTypeName == "indexShow")
            {
                arg.TemplateEntity = MvcWebCacheManager.GetDefaultTemlateEntity();
                arg.TemplateEntity.TemplateName = "indexShow.htm";
            }
            else if (arg.PageHelper.OtherTypeName == "allShow")
            {
                arg.TemplateEntity = MvcWebCacheManager.GetDefaultTemlateEntity();
                arg.TemplateEntity.TemplateName = "allShow.htm";
            }

        }

    }

}
